package cn.luowb.checkchat.dao.mapper;

import cn.luowb.checkchat.dao.entity.CategoryDO;
import cn.luowb.checkchat.dto.resp.CategoryHotVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author heimenkyou
 * @description 针对表【category(分类)】的数据库操作Mapper
 * @createDate 2025-09-01 19:07:09
 * @Entity cn.luowb.checkchat.dao.entity.CategoryDO
 */
public interface CategoryMapper extends BaseMapper<CategoryDO> {

    @Select("select cate_name from category where cate_id = #{cateId}")
    String getCateName(Long cateId);
    @Select("SELECT c.cate_id, c.cate_name FROM category c " +
            "JOIN (SELECT cate_id, COUNT(*) as post_count FROM post WHERE status = 1 GROUP BY cate_id) p " +
            "ON c.cate_id = p.cate_id " +
            "ORDER BY p.post_count DESC " +
            "LIMIT #{limit}")
    List<CategoryHotVO> getHot(int limit);
}




